<UserControl x:Class="WozLib.UI.Controls.OpacitySelector"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="_OpacitySelector"
    >
  <UserControl.Resources>
    <!-- Converter to bind togglebutton state to element visiblity -->
    <BooleanToVisibilityConverter x:Key="B2VC" />

    <ControlTemplate x:Key="RectRadio">
      <Grid Margin="5,5,5,5">
        <Rectangle Fill="#19000000" RadiusX="5" RadiusY="5"/>
        <Rectangle x:Name="SelectedRectangle" Stroke="Blue" StrokeThickness="1.0" RadiusX="5" RadiusY="5"
                   Visibility="{TemplateBinding Property=RadioButton.IsChecked, Converter={StaticResource B2VC}}">
          <Rectangle.Fill>
            <SolidColorBrush>
              <SolidColorBrush.Color>
                <Color ScR="0.85" ScG="0.85" ScB="1.0" ScA="1.0"/>
              </SolidColorBrush.Color>
            </SolidColorBrush>
          </Rectangle.Fill>
          <!--<Rectangle.Fill>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <LinearGradientBrush.GradientStops>
                <GradientStop Color="SlateBlue" Offset="0"/>
                <GradientStop Color="SlateBlue" Offset="0.15"/>
                <GradientStop Color="SlateBlue" Offset="0.70"/>
              </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
          </Rectangle.Fill>-->
        </Rectangle>
        <Rectangle x:Name="MouseOverRectangle" Stroke="Blue" StrokeThickness="1.0" Opacity="0.0" RadiusX="5" RadiusY="5">
          <Rectangle.Fill>
            <SolidColorBrush>
              <SolidColorBrush.Color>
                <Color ScR="0.50" ScG="0.70" ScB="1.0" ScA="1.0"/>
              </SolidColorBrush.Color>
            </SolidColorBrush>
          </Rectangle.Fill>
        </Rectangle>
        <ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" Margin="3"/>
      </Grid>
      <ControlTemplate.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation 
                  Storyboard.TargetName="MouseOverRectangle"
                  Storyboard.TargetProperty="Opacity"
                  To="1" Duration="0:0:0.1"/>
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation 
                  Storyboard.TargetName="MouseOverRectangle"
                  Storyboard.TargetProperty="Opacity"
                  AccelerationRatio="0.2"
                  DecelerationRatio="0.4"
                  To="0" Duration="0:0:0.3"/>
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </UserControl.Resources>


  <Expander>
    <Expander.Header>
      <StackPanel Orientation="Horizontal">
        <RadioButton x:Name="_ZeroRadio" Template="{StaticResource RectRadio}" 
                     Visibility="{Binding ElementName=_OpacitySelector, Path=AllowZero, Converter={StaticResource B2VC}}">
          <Grid>
            <StackPanel Orientation="Horizontal">
              <TextBlock VerticalAlignment="Center" Style="{StaticResource ProperyTextBlock}">0</TextBlock>
              <Border BorderBrush="Black" BorderThickness="1.0" Margin="1.5">
                <Rectangle Width="10" Fill="Blue" Opacity="0.0"/>
              </Border>
            </StackPanel>
          </Grid>
        </RadioButton>
        <RadioButton x:Name="_OneRadio" Template="{StaticResource RectRadio}">
          <Grid>
            <StackPanel Orientation="Horizontal">
              <TextBlock VerticalAlignment="Center" Style="{StaticResource ProperyTextBlock}">0.20</TextBlock>
              <Border BorderBrush="Black" BorderThickness="1.0" Margin="1.5">
                <Rectangle Width="10" Fill="Blue" Opacity="0.20"/>
              </Border>
            </StackPanel>
          </Grid>
        </RadioButton>
        <RadioButton x:Name="_TwoRadio" Template="{StaticResource RectRadio}">
          <Grid>
            <StackPanel Orientation="Horizontal">
              <TextBlock VerticalAlignment="Center" Style="{StaticResource ProperyTextBlock}">0.50</TextBlock>
              <Border BorderBrush="Black" BorderThickness="1.0" Margin="1.5">
                <Rectangle Width="10" Fill="Blue" Opacity="0.50"/>
              </Border>
            </StackPanel>
          </Grid>
        </RadioButton>
        <RadioButton x:Name="_FiveRadio" Template="{StaticResource RectRadio}">
          <Grid>
            <StackPanel Orientation="Horizontal">
              <TextBlock VerticalAlignment="Center" Style="{StaticResource ProperyTextBlock}">1.0</TextBlock>
              <Border BorderBrush="Black" BorderThickness="1.0" Margin="1.5">
                <Rectangle Width="10" Fill="Blue" Opacity="1.0"/>
              </Border>
            </StackPanel>
          </Grid>
        </RadioButton>
        <RadioButton x:Name="_OtherRadio" Template="{StaticResource RectRadio}">
          <TextBlock Style="{StaticResource ProperyTextBlock}">other: </TextBlock>
        </RadioButton>
        <TextBox IsEnabled="{Binding ElementName=_OtherRadio, Path=IsChecked}" 
                 Text="{Binding ElementName=_OpacitySelector, Path=SelectedOpacity, Mode=TwoWay}" 
          Style="{StaticResource ProperyTextBox}" Width="60"/>
      </StackPanel>
    </Expander.Header>

    <StackPanel Orientation="Vertical">
      <StackPanel Orientation="Horizontal">
        <TextBlock>0.05 </TextBlock>
        <Slider x:Name="_SmallSlider" Orientation="Horizontal" Width="170" Minimum="0.00" Maximum="1.00" SmallChange="0.05" LargeChange="0.05" 
          TickFrequency="0.05" TickPlacement="None" IsSnapToTickEnabled="True"      
          Value="{Binding ElementName=_OpacitySelector, Path=SelectedOpacity, Mode=TwoWay}"/>
        <TextBlock> 1.00 </TextBlock>
      </StackPanel>
    </StackPanel>

  </Expander>

</UserControl>
